unit Sounds;

interface

uses              
  Database,
  Windows, Messages, FileCtrl, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, MMSystem, ExtCtrls;

type
  TFormSounds = class(TForm)
    BtnOK: TBitBtn;
    BtnCancel: TBitBtn;
    Files: TFileListBox;
    Dirs: TDirectoryListBox;
    Drives: TDriveComboBox;
    BtnSound: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    Bevel1: TBevel;
    LabelCount: TLabel;
    procedure BtnCancelClick(Sender: TObject);
    procedure BtnSoundClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtnOKClick(Sender: TObject);
    procedure FilesKeyPress(Sender: TObject; var Key: Char);
    procedure FilesChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    sound: string;
  end;

var
  FormSounds: TFormSounds;

implementation

{$R *.DFM}

procedure TFormSounds.FormCreate(Sender: TObject);
var dir: string;
begin
  dir:=Datawell.GetDir(5);
  if not DirectoryExists(dir) then dir:=datawell.getsounddir;
  if not DirectoryExists(dir) then dir:=datawell.exedir;
  dirs.directory:=dir;
end;

procedure TFormSounds.BtnCancelClick(Sender: TObject);
begin
  sound:='';
  close;
end;

procedure TFormSounds.BtnOKClick(Sender: TObject);
begin
  if Files.filename = '' then exit;
  Datawell.SetDir(5,dirs.directory);
  sound:=Files.filename;
  close;
end;

procedure TFormSounds.FilesKeyPress(Sender: TObject; var Key: Char);
begin
  if (key = #13) or (key = #32) then begin
    key:=#0;
    BtnSound.click;
  end;
end;

procedure TFormSounds.BtnSoundClick(Sender: TObject);
var filename: string;
begin
  filename:=Files.filename;
  if not fileexists(filename) then exit;
  sndplaysound(pchar(filename),(snd_async or snd_nodefault));
end;

procedure TFormSounds.FilesChange(Sender: TObject);
begin
  LabelCount.caption:='('+inttostr(Files.items.count)+')';
end;

end.
